package org.dei.perla.aggregates;

import java.util.Iterator;
import java.util.List;

import org.dei.perla.parser.expressions.ConstantFloat;

public class SampleSumSquare implements AggregationOperator {

	@Override
	public ConstantFloat doOperation(ConstantFloat[] sample) {
		double sumSquare = 0;
		double valueFloat = 0;
		int len = sample.length;
		for (int i = 0; i < len; i++) {
			valueFloat = sample[i].getValueFloat();
			sumSquare += valueFloat * valueFloat;
		}
		return new ConstantFloat(sumSquare);
	}

	@Override
	public ConstantFloat doOperation(List<ConstantFloat> sample) {
		double sumSquare = 0;
		double valueFloat = 0;
		Iterator<ConstantFloat> it = sample.iterator();
		while (it.hasNext()) {
			ConstantFloat tConstantFloat = it.next();
			valueFloat = tConstantFloat.getValueFloat();
			sumSquare += valueFloat * valueFloat;
		}
			return new ConstantFloat(sumSquare);
	}

}
